package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

func main() {

	// fmt.Println("hello world")
	conn, err := sql.Open("mysql", "root:hadoop123@tcp(121.196.166.188:3306)/demo")

	if err != nil {
		fmt.Println("数据库连接失败")
	}

	rows, err := conn.Query("select `DNAME` from dept where `deptno` = 20")

	if err != nil {
		fmt.Println("查询数据失败", err.Error())
	}

	//fmt.Println(rows)

	if rows != nil {
		for rows.Next() {
			var name string
			err = rows.Scan(&name)
			if err != nil {
				panic(err.Error())
			}
			fmt.Println(name)
		}
	}

}
